package top.luhancc.retry;

import com.burukeyou.retry.core.FastRetryQueue;
import com.burukeyou.retry.core.RetryQueue;
import com.burukeyou.retry.core.task.RetryTask;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author luHan
 * @create 2025/8/28 10:18
 * @since 1.0.0
 */
public class UseRetryQueue {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(8);
        RetryQueue queue = new FastRetryQueue(executorService);
        RetryTask<String> task = new RetryTask<String>() {
            int result = 0;

            // 下一次重试的间隔
            @Override
            public long waitRetryTime() {
                return 2000;
            }

            // 执行重试，每次重试回调此方法
            @Override
            public boolean retry() {
                return ++result < 5;
            }

            // 获取重试结果
            @Override
            public String getResult() {
                return result + "";
            }
        };
        CompletableFuture<String> future = queue.submit(task);
        System.out.println("任务结束 结果:" + future.get());
    }
}
